#include "chapter1_2.h"

using namespace std;


class TestOverloadOperator
{
public:	
	TestOverloadOperator():_value(0),_index(0) {};
	~TestOverloadOperator() {};

	//overload operator functions
	TestOverloadOperator &operator=(const TestOverloadOperator &);
	TestOverloadOperator &operator*(const TestOverloadOperator &);
	TestOverloadOperator &operator*=(const TestOverloadOperator &);

	void setvalue(int value, int index) {_value = value, _index = index ;};


private:
	int _value;
	int _index;
};


TestOverloadOperator &TestOverloadOperator::operator=(const TestOverloadOperator &rhs)
{
	this->_index = rhs._index;
	this->_value = rhs._value;

	return *this;
}

TestOverloadOperator &TestOverloadOperator::operator*(const TestOverloadOperator &rhs)
{
	this->_index *= rhs._index;
	this->_value *= rhs._value;

	return *this;
}

TestOverloadOperator &TestOverloadOperator::operator*=(const TestOverloadOperator &rhs)
{
	this->_index *= rhs._index;
	this->_value *= rhs._value;

	return *this;
}


bool operator==(const string &str1, const string &str2)
{
	if(str1.size() != str2.size())
		return false;
	return strcmp(str1.c_str(), str2.c_str());

}

string & operator+=(const string &str1, const string &str2)
{
	string str = str1 + str2;

	return str;
}

class absInt
{
public:
	int operator()(int value)
	{
		int result = value > 0 ? value:(-value);
		return result;	
	}


};

void test_overload_operator()
{
	TestOverloadOperator temp, temp2,temp3;


	temp2.setvalue(99,88);

	temp = temp2;

	temp3 = temp * temp2;

	temp =temp2;
	temp *= temp2;

	string a = "yes",b = "no";
	if(a != b)
		a+=b;

	//absInt intvalue = -900;
	printf("%s, %d", __FUNCTION__ , __LINE__);

	int aa = absInt()(-900);
}